<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>创建对象</title>
</head>
<body>
  <script>

    function Dog (type , age , color){
      // 1、new会创建
      // var obj = {}
      // 2、this -> obj

      this.type = type;
      this.age = age;
      this.color = color;
      this.say = function(){
        console.log(this.age)
      }
      // 3、new 会返回这个obj
      // return obj
    }

    // const dog1 = new Dog('柯基' , 1 , 'green')
    // console.log(dog1)
    // dog1.say()

    // 没有new的时候 this指向window
    Dog('二哈' , 2 , 'red')
    say()
    // 这里能出来，是因为，type age color say 直接在window上
    console.log(window)
  </script>
</body>
</html>